package com.suyang.syt.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.suyang.syt.model.dto.solr.SolrFieldTeacher;
import com.suyang.syt.service.interfaces.RebuildIndexService;
import com.suyang.syt.util.SolrUtil;

public class RebuildIndexServiceImpl implements RebuildIndexService {

	@Override
	public void addRebuildIndex() throws Exception {
		// // 1.删除所有索引
		// SolrUtil.deleteByQuery("*:*", false);
		// // 2.查询所有数据,添加索引
		List<SolrFieldTeacher> datas = new ArrayList<SolrFieldTeacher>();
		// TrainingInstitution trainingInstitution = null;
		// List<TrainingInstitution> pxjgs =
		// trainingInstitutionDao.list(" from TrainingInstitution where id > 3 and status=2 and ptext='培训机构'");
		// if (EmptyUtil.isNotEmpty(pxjgs)) {
		// for (TrainingInstitution pxjg : pxjgs) {
		// datas.add(SolrUtil.saveIndex(pxjg,
		// courseTypeDao.findScopes(pxjg.getTeachingScope())));
		// }
		// }
		// List<Teacher> teachers = teacherDao.list(" from Teacher ");
		// if (EmptyUtil.isNotEmpty(teachers)) {
		// for (Teacher teacher : teachers) {
		// long trid =
		// trainingInstitutionTeacherCourseDao.getTridByTeacherId(teacher.getId());
		// trainingInstitution = trainingInstitutionDao.load(trid);
		// if (trainingInstitution != null) {
		// datas.add(SolrUtil.saveIndex(trainingInstitution, teacher,
		// courseTypeDao.findScopes(teacher.getTeacherPro())));
		// }
		// }
		// }
		// List<Course> courses = courseDao.list(" from Course ");
		// if (EmptyUtil.isNotEmpty(courses)) {
		// for (Course course : courses) {
		// long trid =
		// trainingInstitutionTeacherCourseDao.getTridByCourseId(course.getId());
		// trainingInstitution = trainingInstitutionDao.load(trid);
		// if (trainingInstitution != null) {
		// List<Long> ids =
		// trainingInstitutionTeacherCourseDao.listTeacherByCourseId(course.getId());
		// if (EmptyUtil.isNotEmpty(ids)) {
		// for (Long id : ids) {
		// datas.add(SolrUtil.saveIndex(trainingInstitution, id, course,
		// courseTypeDao.load(course.getCtid()).getName()));
		// }
		// }
		// }
		// }
		// }
		SolrUtil.addBeans(datas, false);
		// 3.优化
		SolrUtil.optimize();
		SolrUtil.commit();
	}

}
